(function(){
    function SetPassWord(){};
    SetPassWord.prototype={
        //初始化调用
        init:function(opts){
            this.smsTPL=opts.smsTPL;//短信编码
            this.required_register=opts.required_register||false;//判断是否已经注册
            this.sendPassAjax=opts.sendPassAjax;
            this.opts={
                getCodeBtn:opts.getCodeBtn,//获取验证码按钮
                formInput:opts.formInput,//表单集合
                mobileText:opts.formText.mobileText,//手机号码
                codeText:opts.formText.codeText,//短信验证码
                passText:opts.formText.passText,//密码框
                resetBtn:opts.resetBtn,//重置按钮
                eyeBtn:opts.eyeShow,//密码眼睛
                codeImg:opts.model.codeImg,//图片验证码
                modal:opts.model.modal,//模态框
                modalSure:opts.model.sureBtn,//模态框确定按钮
                modalCancel:opts.model.cancelBtn,//模态框关闭按钮,
                imgTextBox:opts.model.imgTextBox//图像验证码文本框
            };

            //启用重置按钮
            this.formStatus(
                this.opts.formInput,
                this.opts.resetBtn,
                this.opts.codeText,
                this.opts.passText,
                this.opts.mobileText
            );
            //公共方法，密码的显示与隐藏----------------------
            oPublic.eyesPassWord(this.opts.eyeBtn,this.opts.passText);


            //公共方法错误样式样式清楚-----------------------------------
            oPublic.focusCancel(this.opts.formInput);

            //公共方法,弹窗事件----------------------------------
            oPublic.picAlertbox(
                this.opts.getCodeBtn,
                this.opts.modalCancel,
                this.opts.modalSure,
                this.opts.codeImg,
                this.opts.mobileText,
                this.opts.modal,
                this.opts.codeText,
                this.opts.imgTextBox,
                this.smsTPL,
                this.required_register
            );

            //更改密码-------------------------------
            this.alterPass(this.opts.resetBtn,this.opts.formInput);

        },
        formStatus:function(opts,btns,codeText,password,mobileText){
            //键盘抬起判断字数-----------------------
            $(opts).keyup(function(){
                var codeTextValue=$(codeText).val();
                var passLen=$(password).val();
                var telephone=$(mobileText).val();
                if(codeTextValue.length==4){
                    if(passLen.length>=8&&passLen.length<=16&&telephone.length==11){
                        $(btns).attr("disabled",false).addClass("active_status");
                    }else{
                        $(btns).attr("disabled",true).removeClass("active_status");
                    }
                }else{
                    $(btns).attr("disabled",true).removeClass("active_status");
                }
            })
        },
        //更改提交密码
        alterPass:function(resetPassBtn,formInput){
            var self=this;
            $(resetPassBtn).on("click",function(){
                //循环判断正则  模板【data-】-----------------------------------
                var flag=true;
                $(formInput).each(function(){
                    var oValue=$(this).val();
                    var errorMsg=$(this).attr("data-error");
                    var regStr=$(this).attr("data-reg");
                    var reg=new RegExp(regStr);//正则匹配
                    if(reg&&!reg.test(oValue)){
                        oPublic.errorText($(this),errorMsg,"warn","dl",".pass_eye em");
                        flag=false;
                        return;
                    }
                });

                //如果正则验证通过，就像服务器端发送数据---------------
                if(flag){
                    /*
                    *  passData  密码对象
                    *  passData  =>  mobilePhone    用户手机号
                    *  passData  =>  modifyPassWord  修改后的密码
                    *  passData  =>  validateCode  短信验证码
                    * */
                    var passData={
                        mobilePhone:$(self.opts.mobileText).val(),
                        modifyPassWord:$(self.opts.passText).val(),
                        validateCode:$(self.opts.codeText).val()
                    }
                    self.sendPassAjax(passData);//Ajax提交函数
                }
            });
        }
    };
    window.setPassWord=new SetPassWord();
})();